#pragma once

#include "piocore.h"
#include "database.h"
#include "filterbank.h"
#include "iconcache.h"
#include "mediaitemimpl.h"

class MainWindow;
class ImportModule;

class PioCoreImpl : public PioCore
{
    Q_OBJECT
public:
    PioCoreImpl(MainWindow * mainwindow);
    virtual ~PioCoreImpl();
    virtual QMainWindow * mainwindow();
    virtual QToolBar * toolbar();
    virtual QList<MediaItemPtr> all();
    virtual QList<MediaItemPtr> view();
    virtual QList<MediaItemPtr> selection();
    virtual QList<MediaItemPtr> checked();
    virtual QSet<MediaItemPtr> set(MediaItemPtr item);
    virtual bool registerImportModule(ImportModule * im);
    virtual QString libraryPath();
    virtual QSettings & settings();
    virtual QPixmap icon(const MediaItemPtr & item, const QSize & size, bool sync);
    virtual QImage load(const QString & filename, const QSize & size);
    virtual void add(const QString & filename);
    virtual bool trash(MediaItemPtr item);
    virtual bool rename(MediaItemPtr item, const QString & filename);

    virtual void setStatus(const QString & status);
    virtual void import(QUrl url);

    virtual void select(MediaItemPtr item, bool select);
    virtual void check(MediaItemPtr item, bool check);
    virtual void select(QSet<MediaItemPtr> selection);
    virtual void clearSelection();

    virtual void addOverlay(QWidget * overlay);
    virtual void removeOverlay(QWidget * overlay);
    virtual void addToolWidget(QWidget * widget, QString title);
    virtual void removeToolWidget(QWidget * widget);
    virtual void selectToolWidget(QWidget *widget);

    void moveToCollection(MediaItemPtr item, const QString & collection);

    //Library * library();
    Database * database();
    FilterBank * filters();
    IconCache * cache();
    ImportModule * getImportModule(QString scheme);

    static bool newer(const MediaItemPtr & a, const MediaItemPtr & b);

public slots:
    void copyMetadata(MediaItemPtr item, const MediaItemImpl::Metadata & metadata);

private slots:
    void onAdded(MediaItemPtr item);
    void onItemGetInvisible(MediaItemPtr item);
    void onLoaded(MediaItemPtr item, QSize size, QSharedPointer<QPixmap> pm);

private:
    MainWindow * m_mainwindow;
    Database m_database;
    //Library m_library;
    FilterBank m_filters;
    IconCache m_cache;
    QMap<QString, ImportModule*> m_importModules;
    QSettings m_settings;
    QList<QWeakPointer<MediaItem> > m_create_icon_queue;
    QList<MediaItemPtr> m_selection;
    QString m_rootpath;
};
